package com.program.cloudmanage.tripteam.controller;

import com.alibaba.nacos.api.annotation.NacosInjected;
import com.program.cloudmanage.tripteam.domain.Person;
import com.program.cloudmanage.tripteam.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RefreshScope
@RequestMapping("/Person")
public class PersonController {
    @NacosInjected
    @Autowired
    private PersonService personService;

    @GetMapping("/Person")
    public List<Person> showPersons(){
        return personService.showPersons();
    }

    @GetMapping("/test")
    public String test(){
        return "hello world";
    }

    @PostMapping("/searchPerson")
    public Person searchPerson(@RequestBody Person person){
        return personService.searchPerson(person.getPersonid());
    }
    @PostMapping("/searchPersonByTeamId")
    public List<Person> searchPersonByTeamId(@RequestBody Person person){
        return personService.searchPersonByTeamId(person.getTeamid());
    }
     @PostMapping("/searchPersonByCarId")
    public Person searchPersonByCarId(@RequestBody Person person){
        return personService.searchPersonByCarId(person.getTeamid());
    }


    @PostMapping("/insertPerson")
    public String insertPerson(@RequestBody Person person){
        personService.insertPerson(person);
        return "OK";
    }

    @PostMapping ("/deletePerson")
    public String deletePerson(@RequestBody Person person){
        personService.deletePerson(person.getPersonid());
        return "OK";
    }

    @PostMapping("/updatePerson")
    public String updatePerson(@RequestBody Person person) {
        personService.updatePerson(person);
        return "OK";
    }


}